package goutils

import (
	"fmt"
	"os"
	"path"

	ini "gopkg.in/ini.v1"
)

type app_path struct {
	Root       string
	ExeRoot    string
	ConfigFile string
	Cache      string
	Logs       string
}

type app_status struct {
	ErrMsg string
}

var (
	Status  app_status
	Path    app_path
	Version int64
	Config  *ini.File
	Debug   bool
)

func init() {
	Version = 191008
	Debug = true

	Path.Root = GetWorkDir()
	Path.ExeRoot = GetRootDir()

	Path.ConfigFile = path.Join(Path.ExeRoot, "config/config.ini")
	if _, err := os.Stat(Path.ConfigFile); err != nil {
		Path.ConfigFile = path.Join(Path.Root, "config/config.ini")

		if _, err := os.Stat(Path.ConfigFile); err != nil {
			Path.ConfigFile = path.Join(Path.ExeRoot, "config.ini")

			if _, err := os.Stat(Path.ConfigFile); err != nil {
				Path.ConfigFile = path.Join(Path.Root, "config.ini")
			}
		}
	}

	Path.Cache = path.Join(Path.ExeRoot, "cache")
	Path.Logs = path.Join(Path.ExeRoot, "logs")

	// Init_log(Path.Logs)

	var err error
	// Config, err = ini.Load("config/config.ini")
	Config, err = ini.Load(Path.ConfigFile)
	if err != nil {
		fmt.Printf("Fail to read config file: %v", err)
		os.Exit(1)
	}

}
